package com.dqhl.community.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.model.FamilyServiceRecordBean;
import com.dqhl.community.util.ViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2016/9/11.
 */
public class FamilyServiceRecordAdapter extends BaseAdapter {
    private Context context;
    private List<FamilyServiceRecordBean> list;
    private LayoutInflater inflater;
    private onCompleteListener onCompleteListener;
    public FamilyServiceRecordAdapter(Context context, List<FamilyServiceRecordBean> list,onCompleteListener onCompleteListener) {
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
        this.onCompleteListener = onCompleteListener;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = inflater.inflate(R.layout.layout_itme_repairrecord, viewGroup, false);
        }
        TextView tvCommunity = ViewHolder.get(view, R.id.tv_community);
        TextView tvTime = ViewHolder.get(view, R.id.tv_time);
        TextView tvName = ViewHolder.get(view, R.id.tv_owner_name);
        TextView tvTelephone = ViewHolder.get(view, R.id.tv_telephone);
        TextView tvAddress = ViewHolder.get(view, R.id.tv_address);
        TextView tv_appliance = ViewHolder.get(view, R.id.tv_appliance);
        ImageView iv_complete = ViewHolder.get(view, R.id.iv_complete);
        FamilyServiceRecordBean familyServiceRecord = list.get(i);

        tvCommunity.setText(familyServiceRecord.getLocation());
        tvTime.setText(familyServiceRecord.getOrder_time());
        tvName.setText(familyServiceRecord.getH_name());
        tvTelephone.setText(familyServiceRecord.getH_phone());
        tvAddress.setText(familyServiceRecord.getAddress());
        tv_appliance.setText(familyServiceRecord.getType());
        // 1  未完成   2  已完成
        if("1".equals(familyServiceRecord.getState())){
            iv_complete.setImageResource(R.drawable.ic_complete_record);
        }else{
            iv_complete.setImageResource(R.drawable.ic_complete_ready);
        }
        iv_complete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onCompleteListener.onComplete(i);
            }
        });
        return view;
    }
    public interface onCompleteListener{
        void onComplete(int position);
    }
}
